package com.yonyou.biz.actions;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.yonyou.common.dialog.CustomDialogWrapper;
import com.yonyou.utils.GitUtils;
import git4idea.GitLocalBranch;
import git4idea.branch.GitBranchUtil;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.stream.Collectors;

public class ChrryPickCustomerDialogAction extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent e) {
        Project project = e.getProject();
        try {
            GitRepositoryManager manager = GitRepositoryManager.getInstance(project);
            GitRepository   repository = GitBranchUtil.getCurrentRepository(project);
            GitLocalBranch localBranch = repository.getCurrentBranch();
            String branchName = localBranch.getName();
            List<String> localBranchList = GitUtils.getCurrentBranchList(project);;

            java.util.LinkedHashMap linkedHashMap = new LinkedHashMap<>();
            linkedHashMap.put("全选","全选");
            for (String branch : localBranchList) {
                if(!branch.equals(branchName)){
                    linkedHashMap.put(branch,branch);
                }
            }

            CustomDialogWrapper dialog = new CustomDialogWrapper(project,manager,repository,linkedHashMap);

            dialog.setResizable(true); //是否允许用户通过拖拽的方式扩大或缩小你的表单框，我这里定义为true，表示允许
            dialog.show();
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }

    }
}
